﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeTunnel.MvcUtilities.Utilities
{
    /// <summary>
    /// Useful utilities related to Markdown.
    /// </summary>
    public static class MarkdownUtils
    {
        /// <summary>
        /// Transforms Markdown syntax into valid HTML.
        /// </summary>
        /// <param name="markdownText">The text to be transformed.</param>
        /// <returns>string</returns>
        public static string FormatMarkdown(string markdownText, bool sanitize)
        {
            var markdown = new Markdown
            {
                AutoHyperlink = true,
                EncodeCodeBlocks = !sanitize,
                LinkEmails = true,
                EncodeProblemUrlCharacters = true,
                EmptyElementSuffix = " />"
            };
            string html = markdown.Transform(markdownText);
            if (sanitize)
                html = CommonUtils.Sanitize(html);
            return html;
        }
    }
}
